import { Prefab } from 'cc';
import { Sprite } from 'cc';
import { instantiate } from 'cc';
import { Label } from 'cc';
import { _decorator, Component, Node } from 'cc';
import { App } from '../../../App';
import GameUtils2 from './GameUtils2';
import { find } from 'cc';
import { tween } from 'cc';
import { Vec2 } from 'cc';
import { Vec3 } from 'cc';
import { Tween } from 'cc';
import { TweenAction } from 'cc';
import { BLACK_BALL } from '../GameManage';
import UtilTool from '../../../tools/UtilTool';
const { ccclass, property } = _decorator;

@ccclass('BallInfoNode')
export class BallInfoNode extends Component {

    @property(Label)
    label_name : Label = null

    @property(Node)
    balls : Node = null

    @property(Prefab)
    ball_item : Prefab = null

    nameBg : Node = null
    tipActionTween : Tween<any> = null

    protected onLoad(): void {
        this.nameBg = find('name_bg', this.node)

        this.tipActionTween = UtilTool.showBreatheAction(this.nameBg, false)

        this.label_name.string = ""
        this.balls.removeAllChildren()
    }

    start() {
    }

    setData(ballList) {
        this.balls.removeAllChildren()
        
        ballList.forEach(item => {
            let node = instantiate(this.ball_item)

            if(item < BLACK_BALL) {
                let spDict = GameUtils2.getRes("images/ball2D_2")
                node.getComponent(Sprite).spriteFrame = spDict["ball2d_" + item]
            } else {
                let bigDict = GameUtils2.getRes("images/ball2D")
                node.getComponent(Sprite).spriteFrame = bigDict["ball2d_" + item]
            }

            node.parent = this.balls
        })

    }

    setName(name) {
        this.label_name.string = name
    }

    showActionAnim(isShow=true) {

        if(isShow) {
            this.tipActionTween.start()
        } else{
            this.tipActionTween.stop()
        }
        
    }


    update(deltaTime: number) {
        
    }
}

